package com.attendance.controller;

import com.attendance.result.LayuiMiniPage;
import com.attendance.security.info.pojo.LoginInfo;
import com.attendance.security.info.service.LoginInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.security.RolesAllowed;

/**
 * 登录信息控制器
 *
 * @author 今朝
 * @date 2021/03/18
 */
@Controller
@RequestMapping("/system/lginfo")
@RolesAllowed("ADMIN")
public class LoginInfoController {

    @Autowired
    LoginInfoService loginInfoService;

    @GetMapping()
    public String table() {
        return "/system/lginfo/table";
    }

    @ResponseBody
    @GetMapping("/listPage")
    public LayuiMiniPage<LoginInfo> getListPage(Integer page, Integer limit, String searchParams) {
        if (searchParams != null) {
            Page<LoginInfo> listPage = loginInfoService.getListPage(page, limit, searchParams);
            return new LayuiMiniPage<>(200, "查询成功", listPage.getTotal(), listPage.getRecords());
        }
        Page<LoginInfo> listPage = loginInfoService.getListPage(page, limit);
        return new LayuiMiniPage<>(200, "查询成功", listPage.getTotal(), listPage.getRecords());
    }
}
